package org.pixelami.twisted.spread.flavors
{
	import org.pixelami.twisted.spread.jelly.Unjellyable;
	import org.pixelami.twisted.spread.jelly.__jelly__;
	
	public class RemoteCopy extends Unjellyable
	{
		/*
		"""I am a remote copy of a Copyable object.

	    When the state from a L{Copyable} object is received, an instance will
	    be created based on the copy tags table (see setUnjellyableForClass) and
	    sent the L{setCopyableState} message.  I provide a reasonable default
	    implementation of that message; subclass me if you wish to serve as
	    a copier for remote data.
	
	    NOTE: copiers are invoked with no arguments.  Do not implement a
	    constructor which requires args in a subclass of L{RemoteCopy}!
	    """
		*/
		
		public function RemoteCopy()
		{
		}
		
		public function setCopyableState(state:Object):void
		{
	        /*
	        """I will be invoked with the state to copy locally.
	
	        'state' is the data returned from the remote object's
	        'getStateToCopyFor' method, which will often be the remote
	        object's dictionary (or a filtered approximation of it depending
	        on my peer's perspective).
	        """
			*/
	        this.__dict__ = state;
	 	}
	
	    override public function unjellyFor(unjellier:Object, jellyList:Array):*
	    {
	        if (unjellier.invoker == null)
	        {
	            return __jelly__.setInstanceState(this, unjellier, jellyList);
	        }
	        this.setCopyableState(unjellier.unjelly(jellyList[1]));
	        return this;
	    }

	}
}

